<?php
class Default_Model_DbTable_Category extends Zend_Db_Table_Abstract {
	protected $_name = 'category';
	public function addCategory($parent_id, $Category_name, $description , $img , $status) {
		$data = array (
				'PARENT_ID' => $parent_id,
				'CAT_NAME' => $Category_name,
				'CAT_DESC' => $description,
				'IMG'=>$img,
				'STATUS' => $status 
		);
		return $this->insert ( $data );
	}
	public function updateCategory($id, $parent_id, $Category_name, $description, $img , $status) {
		$data = array (
				'PARENT_ID' => $parent_id,
				'CAT_NAME' => $Category_name,
				'CAT_DESC' => $description,
				'IMG'=>$img,
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function removeCategory($id) {
		return $this->delete ( "ID = $id" );
	}
	
	public function getParentCategory($Category_id, $status) {
		return $this->fetchRow("ID = $Category_id And STATUS = $status");
	}
	public function getCategoryByParent($parent_Category_id, $status) {
		return $this->fetchAll("PARENT_ID = $parent_Category_id And STATUS = $status","ID DESC");
	}
	public function getAllCategory() {
		return $this->fetchAll ("STATUS = 1","ID DESC")->toArray ();
	}
	public function getCategoryByName($category_name) {
		return $this->fetchRow ( "CATEGORY_NAME = $category_name" );
	}
	public function getCategoryById($category_id) {
		return $this->fetchRow ( "ID = $category_id" );
	}
	public function getCategoryByStatus($status) {
		//$SQL = $this->select()->from("category",array("ID"))->where("STATUS = $status and CATEGORY_NAME = 'dich vu'");
		//return $this->fetchAll($SQL)->toArray();
		return $this->fetchAll("STATUS = $status","ID DESC");
	}
	public function updatestt($id){
		$cat = $this->fetchRow("ID = $id");
		if($cat->STATUS == 1){
			$this->update(array("STATUS"=>"0"), "ID = $id");
		}
		else{
			$this->update(array("STATUS"=>"1"), "ID = $id");
		}
	}
	
// 	public function test() {
// 		$select = $this->select ();
// 		$select->where ( "ID= 1 OR CATEGORY_DESCRIPTION= 'sss'" );
// 		$result = $this->fetchRow ( $select );
// 		return $result;
// 	}
}

